$(document).ready(function(){
	
	loadRequestType();
	loadRequestStatus();
	
	$("#clear").click(function(){
//		$('#inputRequestStatus').val("");
//		$('#inputRequestType').val("");
		document.getElementById("inputRequestStatus").selectedIndex = "0";
		document.getElementById("inputRequestType").selectedIndex = "0";
		$('#datetimepicker2').val("");
		$('#datetimepicker1').val("");
	});
	
});



function loadRequestType() {
	
	$.ajax({
		url : 'CS66000Srvl' , 
		type : "POST",
		data : {
			process_type: "getRequestType" , 
		},
//		anync:false,
		dataType:"JSON",
		success: function(data){
			var selected="";
			var options = '';
			options += '<option value="all">ทั้งหมด</option>';
			for (var i = 0; i < data.values.length; i++) {
				options += '<option value="' + data.values[i] + '" '+selected+'>' + data.messages[i] +  '</option>';
			}
			$("select#inputRequestType").html(options);
		}
	});
}
function loadRequestStatus(){
	$.ajax({
		url: 'CS66000Srvl',
		type: 'POST',
		data: {
			process_type: 'getRequestStatus'
		},
		dataType: 'JSON',
		success: function(data){
			var selected="";
			var options = '';
			options += '<option value="all">ทั้งหมด</option>';
			for (var i = 0; i < data.values.length; i++) {
				options += '<option value="' + data.values[i] + '" '+selected+'>' + data.messages[i] +  '</option>';
			}
			$("select#inputRequestStatus").html(options);
		}
		
	});
	
}

function printReport() {
	
	var vaDateStart = $("#datetimepicker1").val();
	var vaDateEnd = $("#datetimepicker2").val();
	var vaInputRequestType = $("#inputRequestType").val();
	var vaInputRequestStatus = $("#inputRequestStatus").val();
	var vaInputRequestGroup = 0;
	var vnUserId = $("#userId").val();
	var vnSiteId = $("#siteId").val();
	
	if(vaDateStart.trim().length == 0 || vaDateEnd.trim().length == 0 || vaInputRequestType.trim().length == 0 
			|| vaInputRequestStatus.trim().length == 0)
	{
		$("#modal_content").html("กรุณากรอกข้อมูลให้ครบถ้วน");
		$("#warningModal").modal();
		return;
	}else{
		if(vaInputRequestType=="03"){
			vaInputRequestGroup = 1;
		}
		
		var url = reporturl+"CS66000R.jsp?siteId="+vnSiteId+"&userId="+vnUserId+"&fromDate="+vaDateStart+"&toDate="+vaDateEnd+"&requestGroup="+vaInputRequestGroup+"&requestType="+vaInputRequestType+"&statusR="+vaInputRequestStatus;
		window.open(url);
	}
	
}








